import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'


const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
      {
        path: "hot",
        name: "Hot",
        component: () => import("../news/hot.vue")
      }, {
        path: "paihang",
        name: "Paihang",
        component: () => import("../news/paihang.vue")
      }, {
        path: "gedan",
        name: "Gedan",
        component: () => import("../news/gedan.vue")
      }, {
        path: "diantai",
        name: "Diantai",
        component: () => import("../news/diantai.vue")
      }, {
        path: "singer",
        name: "Singer",
        component: () => import("../news/singer.vue")
      }, {
        path: "newsing",
        name: "Newsing",
        component: () => import("../news/newsing.vue")
      },
      {
        path: "/detail",
        name: "Detail",
        component: () => import("@/news/detail")
      },
      {
        path: "/gedanxiang",
        name: "Gedanxiang",
        component: () => import("@/news/gendan")
      }
    ]
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: "/friend",
    name: "Friend",
    component: () => import("../views/friend.vue")
  },
  {
    path: "/down",
    name: "Down",
    component: () => import("../views/down.vue")
  },
  {
    path: "/login",
    name: "Login",
    components: () => import("../views/login.vue")
  },
  {
    path: "/404",
    name: "NotFound",
    component: () => import("@/views/404.vue") //lazy-load
  },
  // 404放到最后配置
  //因为404 所有的路由都匹配不上 才走 404
  {
    // path:"*",  v2可以的
    path: '/:pathMatch(.*)/',  //v3 的写法
    // redirect:"/404"  //重定向 上面所有的 path 都匹配不上的话 会重定向到 /404
    redirect: {
      name: "NotFound" //命名路由
    }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
